package com.nanuminc.market.today.detail;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.TextView;

import com.nanuminc.market.NMConstants;
import com.nanuminc.market.R;

public class DetailFullView_ngoc_galary_bk extends Activity {

	TextView product_info_text;
	int pos;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.todaydetailfullview_ngoc);
        
        Intent i = getIntent(); //get the intent that starts this activity
        pos = i.getIntExtra("gallery_pos", 0); //get the extra variable that put before by TodayDetailView_ngoc activity
        // Reference the Gallery view
        Gallery g = (Gallery) findViewById(R.id.productgallery_full);
        // Set the adapter to our custom adapter (below)
        g.setAdapter(new ImageAdapter(this));       
        // We also want to show context menu for longpressed items in the gallery
        registerForContextMenu(g);	
        
        product_info_text = (TextView) findViewById(R.id.text_product_infomation_full);
		product_info_text.setText(NMConstants.productinfo[pos]);	
	}	
    public class ImageAdapter extends BaseAdapter {
        private static final int ITEM_WIDTH = 136;
        private static final int ITEM_HEIGHT = 88;
        private final int mGalleryItemBackground;
        private final Context mContext;
        
        private final Integer[] mImageIds = {      		
        		//NMConstants.mImageIds[NMConstants.Position] //Ngocdtd Add photos to Gallery. list of images contains only 1 images.
        		NMConstants.mImageIds[pos]
        };
        private final float mDensity;

        public ImageAdapter(Context c) {
            mContext = c;
            // See res/values/attrs.xml for the <declare-styleable> that defines
            // Gallery1.
            TypedArray a = obtainStyledAttributes(R.styleable.Gallery1);
            mGalleryItemBackground = a.getResourceId(
                    R.styleable.Gallery1_android_galleryItemBackground, 0);
            a.recycle();

            mDensity = c.getResources().getDisplayMetrics().density;
        }

        public int getCount() {
            return mImageIds.length;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView;
            if (convertView == null) {
                convertView = new ImageView(mContext);

                imageView = (ImageView) convertView;
                imageView.setScaleType(ImageView.ScaleType.FIT_XY);
                imageView.setLayoutParams(new Gallery.LayoutParams(
                       570,450));// 570,500));            
                // The preferred Gallery item background
                imageView.setBackgroundResource(mGalleryItemBackground);
            } else {
                imageView = (ImageView) convertView;
            }
            imageView.setImageResource(mImageIds[position]);
            return imageView;        
        }  
        };
	//This method is for dragging mouse to view images on todayfullview_ngoc layout
}

